#ifndef __RING_BUFFER_H__
#define __RING_BUFFER_H__

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

#define RingBuff_MAX_SIZE 256 // 队列容量，可调整

typedef enum
{
    RingBuff_DISCARD_NEW = 0,  // 队列满时丢弃新数据
    RingBuff_OVERWRITE_OLD = 1 // 队列满时覆盖旧数据
} RingBuff_FullPolicy;

typedef struct
{
    uint32_t buffer[RingBuff_MAX_SIZE];
    volatile uint8_t head; // 写入指针
    volatile uint8_t tail; // 读取指针
    volatile uint32_t count;
    RingBuff_FullPolicy policy;
} RingBuffer_Def;

// 初始化
void RingBuff_Init(RingBuffer_Def *rb, RingBuff_FullPolicy policy);

// 清空
void RingBuff_Clear(RingBuffer_Def *rb);

// 当前元素个数
uint8_t RingBuff_Count(RingBuffer_Def *rb);

// 从尾部写入（push_back）
bool RingBuff_PushBack(RingBuffer_Def *rb, uint32_t val);

// 从头部写入（push_front）
bool RingBuff_PushFront(RingBuffer_Def *rb, uint32_t val);

// 从头部读取（pop_front）
bool RingBuff_PopFront(RingBuffer_Def *rb, uint32_t *val);

// 从尾部读取（pop_back）
bool RingBuff_PopBack(RingBuffer_Def *rb, uint32_t *val);

#endif // __RING_BUFFER_H__
